<!--
* author: zhanghuan
* created: 2018/1/12
* describe: 第一种布局，用于登录页面
-->
<template>
  <div class="layout-one">
    <div class="layout-one-header fix">
      <router-link
        to="/"
        class="title-cnt fl"
      >
        <h1 class="title">
          <span class="fl">{{title}}</span>
        </h1>
      </router-link>
      <div class="right-btn fr">
        <a href="javascript:;" onclick="SetHome(this)">设为首页</a>
        |
        <span @click="addFavorite">加入收藏</span>
      </div>
    </div>
    <div class="layout-one-body">
      <router-view />
    </div>
    <div class="layout-one-footer"></div>
  </div>
</template>

<script type="text/ecmascript-6">
import Config from '../js/config'
export default {
  name: "layoutOne",
  data() {
    return {
      title: Config.title
    }
  },
  methods: {
    /*
    * params: 无
    * return: 无
    * function: 初始化
    * */
    init() {
      window.SetHome = this.setHome
    },
    /*
    * params: 无
    * return: 无
    * function: 加入收藏
    * */
    addFavorite() {
      let sURL = window.location
      let sTitle = window.document.title
      try {
        window.external.addFavorite(sURL, sTitle)
      } catch (e) {
        try {
          window.sidebar.addPanel(sTitle, sURL, "")
        } catch (e) {
          this.$alert('您的浏览器不支持，请按 Ctrl+D 手动收藏！', '信息', {
            confirmButtonText: '确定',
            callback: action => {

            }
          })
        }
      }
    },
    /*
    * params: 无
    * return: 无
    * function: 设为首页
    * */
    setHome(obj) {
      let vrl = window.location
      try {
        obj.style.behavior = 'url(#default#homepage)'
        obj.setHomePage(vrl)
      }
      catch (e) {
        if (window.netscape) {
          try {
            window.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
          }
          catch (e) {
            this.$alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。", '信息', {
              confirmButtonText: '确定',
              callback: action => {

              }
            })
          }
          var prefs = window.Components.classes['@mozilla.org/preferences-service;1'].getService(window.Components.interfaces.nsIPrefBranch)
          prefs.setCharPref('browser.startup.homepage', vrl)
        } else {
          this.$alert('您的浏览器不支持！', '信息', {
            confirmButtonText: '确定',
            callback: action => {

            }
          })
        }
      }
    }
  },
  mounted() {
    this.init()
  }
}
</script>

<style scoped lang="scss">
@import "../style/variables.scss";
.layout-one {
  height: 100vh;
  background: #fff;
  .layout-one-header {
    height: 106px;
    padding: 0 50px;

    .title-cnt {
      margin-top: 36px;
    }
    .title {
      font-size: 30px;
      font-weight: bold;
      color: $titC;

      .logo {
        height: 36px;
        margin: 3px 10px 0 2px;
      }
    }
    .right-btn {
      line-height: 106px;
      margin-right: 112px;
      user-select: none;
      a,
      span {
        color: $fontC;
        padding: 0 6px;
        cursor: pointer;
        &:hover {
          color: $mainC;
        }
      }
    }
  }
  .layout-one-body {
  }
}
</style>
